package horse;

public class Horselength extends Horse implements iFindWay
{
	public Horselength(int size_x, int size_y)
	{
		super( size_x, size_y);
	}
	
	private boolean step( int x ,int y )
	{
		Area current, next;
		
		if (step>MaxStep) return false;
			
		for (int i=0; i<8; i++)
		{
			current = area.get(step);
			
			if ( current.checkEnd( x+moves[i][0], y+moves[i][1] )) 
			{
				ways.add(current, step+1);
				return true;
			}
			else
			{
				if (current.checkStep( x+moves[i][0], y+moves[i][1] ))  
				{
					next = current.clone();
					next.setValue( x+moves[i][0], y+moves[i][1], step+1 );
					area.add( next );
					step++;
					
					step( x+moves[i][0], y+moves[i][1] );
				}
			}
		}
		
		return false;
	}
	
	@Override
	public boolean find( int x ,int y, int x1, int y2)
	{
		Area init = area.get(0);
		init.setStartPoint(x, y);
		init.setEndPoint(x1, y2);
		area.set(0, init);
		
		step = 0;
		
		step( x+2 , y+2 );
		
		if (ways.size()>0)
		{
			return true;
		}
		
		return false;
	}
}
